package com.laikan.reader.core.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.laikan.reader.core.LaikanBaseAdapter;
import com.laikan.reader.R;
import com.laikan.reader.core.bean.ShareReadBean;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

/**
 * 分享礼包适配器
 *
 * @author Administrator
 */
public class ShareReadGiftsAdapter extends LaikanBaseAdapter<ShareReadBean> {

    private SimpleDateFormat df = new SimpleDateFormat("yyyy年MM月dd日", Locale.getDefault());

    public ShareReadGiftsAdapter(Context mContext) {
        super(mContext);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup arg2) {
        ViewHolder holder = null;
        if (convertView == null) {
            // 获取控件
            holder = new ViewHolder();
            convertView = View.inflate(mContext, R.layout.my_share_read__gifts_item, null);
            holder.iv_icon = (ImageView)convertView.findViewById(R.id.iv_icon);
            holder.tv_name = (TextView)convertView.findViewById(R.id.top_book_name);
            holder.tv_date = (TextView)convertView.findViewById(R.id.tv_date);
            holder.tv_status = (TextView)convertView.findViewById(R.id.tv_status);
            convertView.setTag(holder);

        }else {
            holder = (ViewHolder)convertView.getTag();
        }

        try {
            ShareReadBean b = datas.get(position);
            if (b != null) {
                if (!b.isReceived()) {
                    // 不为空并且未领取该礼包
                    holder.iv_icon.setImageResource(R.drawable.share_read_ico_un);
                    holder.tv_name.setText("神秘大礼在礼包中");
                    holder.tv_name.setTextColor(mContext.getResources().getColor(R.color.C_333333));
                    holder.tv_status.setText("可领取");
                    holder.tv_status.setTextColor(mContext.getResources().getColor(R.color.C_EE5048));

                }else {
                    // 不为空,已领取该礼包
                    holder.iv_icon.setImageResource(R.drawable.share_read_ico_ed);
                    holder.tv_name.setText(b.getShareReadSendQuan() + "阅读券");
                    holder.tv_status.setText("已领取");
                    holder.tv_status.setTextColor(mContext.getResources().getColor(R.color.C_999999));
                }
                holder.tv_date.setText(df.format(new Date(Long.valueOf(b.getShareReadReceiveTime()))));
            }

        }catch (Exception e) {
            e.printStackTrace();
        }
        return convertView;
    }

    private class ViewHolder {

        private ImageView iv_icon;
        private TextView tv_name;
        private TextView tv_date;
        private TextView tv_status;
    }

}
